package top.riske.animalhazardassessment.common.http.exception;

import lombok.Getter;
import org.springframework.http.HttpStatus;

/**
 * 业务异常
 */
@Getter
public class BusinessException extends RuntimeException {

    /**
     * 状态码,使用HttpStatus构造时，会有此状态码
     */
    private final HttpStatus httpStatus;

    public BusinessException(HttpStatus httpStatus) {
        super(httpStatus.getReasonPhrase());
        this.httpStatus = httpStatus;
    }

    public BusinessException(HttpStatus httpStatus, String message) {
        super(httpStatus.getReasonPhrase()+":"+message);
        this.httpStatus = httpStatus;
    }

    /**
     * 默认400错误
     */
    public BusinessException(String message) {
        super(message);
        this.httpStatus = HttpStatus.BAD_REQUEST;
    }

    public int getStatus(){
        return httpStatus.value();
    }

}
